﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using UniversityStudentManagemnetSystem.DAO.DAL;
using UniversityStudentManagemnetSystem.DAO.Gateway;

namespace UniversityStudentManagemnetSystem.BLL
{
    public class CourseEnrollManager
    {
        private StudentCourseEnrollGateway enrollGateway = new StudentCourseEnrollGateway();
        public Student SearchStudentByRegNo(string regNo)
        {
           Student aStudent= enrollGateway.SearchStudentByRegNo(regNo);
           return aStudent;

        }

        internal DataTable GetAllCourseForSelectedDepartment(string departmentId)
        {
            DataTable courseTable = enrollGateway.GetAllCoursesForSelectedDepartment(departmentId);
            return courseTable;
        }

        internal string SaveStudentInformation(Student aStudent, out string message)
        {
            if (aStudent.RegNo=="" )
            {
                message = "RegNo Missing";
                throw new Exception(message);
            }
            else if(aStudent.Name=="" && aStudent.Email=="")
            {
                message = "Name & Email is Missing";
                throw new Exception(message);
            }
            else if (enrollGateway.HasThisCourseEnroll(aStudent))
            {
                message = "This Course AlreadY Enroll To:\t " +aStudent.Name ;
                throw new Exception(message);
            }
            
            else
            {
                enrollGateway.SaveStudentEnrollCourses(aStudent);

                message = "Course Code :" + aStudent.Course.Code + "\tAddad To : " + aStudent.Name;
            }
            return message;
        }


        public DataTable GetAllEnrollCourses(string studentRegNo, out string message)
        {
          DataTable table= enrollGateway.GetAllEnrollCoursesForRegNo(studentRegNo);
          message = "Enroll Courses For Registation No: \t" + studentRegNo;
          return table;
        }
    }
}